home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / dialgmgr.sit / Dialogs ƒ / KeyGroup.p < prev    next >
Text File  |  1989-11-29  |  2KB  |  110 lines

  1. unit TKeyGroup;
  2.  
  3. {        ⌐1986-1989            Bill Stackhouse                                    }
  4. {                                Stackhouse Software                                }
  5. {                                Natick, MA 01760                                    }
  6.  
  7. interface
  8.  
  9. {$IFC UNDEFINED UseKeyGroup}
  10. {$SETC UseKeyGroup = FALSE}
  11. {$ENDC}
  12. {$IFC UseKeyGroup}
  13.  
  14.     uses
  15.         TObject;
  16.  
  17.     const
  18.         maxKeys = 25;
  19.  
  20.     type
  21.         TKeyGroup = object(TObject)
  22.                 numKeyGroups: 0..maxKeys;                {number of key/button groups}
  23.                 KeyGroup: array[1..maxKeys] of record
  24.                         key: char;                                    {command key character to press to activate}
  25.                         btn: Integer;                                {this button}
  26.                     end;
  27.                 procedure TKeyGroup.Init;
  28.                 procedure TKeyGroup.Add (pKey: char;
  29.                                             pBtn: Integer);
  30.                 function TKeyGroup.Click (theKey: Char): Integer;
  31.                 function TKeyGroup.Error: Integer;
  32.             end;
  33.  
  34. {$ENDC}
  35.  
  36. implementation
  37.  
  38. {$IFC UseKeyGroup}
  39.  
  40.     const
  41.         Off = 0;
  42.         On = 1;
  43.  
  44.         btnCtrlItem = 4;
  45.         chkCtrlItem = 5;
  46.         radCtrlItem = 6;
  47.         editCtrlItem = 16;
  48.  
  49.         DialogGroupIgnored = -10;    {too many groups, key, menus, or user items were added}
  50.  
  51.     type
  52.         TSearch = (searching, found, endList);
  53.  
  54.     var
  55.         globalError: Integer;
  56.  
  57.     procedure TKeyGroup.Init;
  58.     begin
  59.         globalError := noErr;
  60.         SELF.numKeyGroups := 0;
  61.     end;        {TKeyGroup.Init}
  62.  
  63.     procedure TKeyGroup.Add (pKey: char;
  64.                                     pBtn: Integer);
  65.     begin
  66.         globalError := noErr;
  67.         with SELF do
  68.             if numKeyGroups < maxKeys then
  69.                 begin
  70.                     numKeyGroups := numKeyGroups + 1;
  71.                     with KeyGroup[numKeyGroups] do
  72.                         begin
  73.                             key := pKey;
  74.                             btn := pBtn;
  75.                         end;
  76.                 end
  77.             else
  78.                 globalError := DialogGroupIgnored;
  79.     end;        {TKeyGroup.Add}
  80.  
  81.     function TKeyGroup.Click (theKey: Char): Integer;
  82.         var
  83.             index: Integer;
  84.             state: TSearch;
  85.     begin
  86.         globalError := noErr;
  87.         state := searching;
  88.         index := 1;
  89.         repeat
  90.             if (SELF.KeyGroup[index].key = theKey) then
  91.                 state := found
  92.             else if index > SELF.numKeyGroups then
  93.                 state := endList
  94.             else
  95.                 index := index + 1;
  96.         until (state <> searching);
  97.         if (state = found) then
  98.             Click := SELF.KeyGroup[index].btn
  99.         else
  100.             Click := 0;
  101.     end;        {TKeyGroup.Key}
  102.  
  103.     function TKeyGroup.Error: Integer;
  104.     begin
  105.         Error := globalError;
  106.     end;        {TKeyGroup.Error}
  107.  
  108. {$ENDC}
  109.  
  110. end.